<template>
  <div class="mine_parent">
    <!-- 头像部分 -->
    <div class="avatar">
      <!-- 左侧头像 用户 -->
      <div class="username">
        <!-- 头像 -->
        <div class="left">
          <van-image round width="3rem" height="3rem"
            src="https://img0.baidu.com/it/u=3921863690,888097025&fm=253&fmt=auto&app=138&f=JPEG?w=400&h=400" />
        </div>
        <!-- 文字 -->
        <div class="right" style="margin-left: 10px;">
          <div style="font-weight: bold;font-size: 14px;font-family:'楷体';">我不是柳白猿</div>
          <div>
            <van-button color="#736d6d" size="small" style="height:20px;" plain round type="default">Lv9.0</van-button>
          </div>
        </div>
      </div>
      <!-- 右侧箭头 -->
      <div class="icon">
        <van-icon name="arrow" size="20" />
      </div>
    </div>
    <!-- 完成宫格部分 -->
    <div class="grid" style="margin-top: 20px;">
      <van-grid square :border="false">
        <van-grid-item icon-color="red" v-for="item in gridList" :key="item.id" :icon="item.icon"
          :text="item.text" @click="openGrid(item)" />
      </van-grid>
    </div>
    <!-- 我喜欢的音乐 -->
    <div class="music">
      <div class="left" style="display: flex;">
        <!-- 图标 -->
        <div class="icon">
          <van-icon name="like" color="#fff" />
        </div>
        <!-- 我喜欢音乐文字 -->
        <div class="text" style="margin-left:10px;">
          <div style="font-weight: bold;margin-bottom: 6px;">我喜欢的音乐</div>
          <div style="color: #736d6d;font-size: 12px;">88首</div>
        </div>
      </div>
      <div class="right">
        <van-button size="mini" icon="fire" plain round type="default" @click="playHeartMode">心动模式</van-button>
      </div>
    </div>

    <!-- 歌单部分 -->
    <div class="card" style="margin-top: 10px;">
      <van-tabs v-model:active="active" animated color="red" background="#f4f4f4">
        <van-tab title="创建歌单" name="a">
          <div class="tab">
            <div class="top">
              <div class="left" style="font-size: 12px;color: #736d6d;">创建歌单(3个)</div>
              <div class="right">
                <van-icon name="plus" color="#736d6d" size="18"></van-icon>
                <van-icon name="bars" color="#736d6d" size="18" style="margin-left: 5px;"></van-icon>
              </div>
            </div>
            <div class="bottom" v-for="item in playList" :key="item.id">
              <div class="left">
                <img width="45px" height="45px" :src="item.url" alt="" class="playlist-cover" @click="openPlaylist(item)">
              </div>
              <div class="right">
                <div style="font-weight: bold; cursor: pointer" @click="openPlaylist(item)">{{ item.name }}</div>
                <div style="font-size: 12px;color: #736d6d;margin-top: 3px;">{{ item.num }}首</div>
              </div>
            </div>  
          </div>
        </van-tab>
        <van-tab title="收藏歌单" name="b">
          <div class="tab">
            <div class="top">
              <div class="left" style="font-size: 12px;color: #736d6d;">收藏歌单(4个)</div>
              <div class="right">
                <van-icon name="search" color="#736d6d" size="18"></van-icon>
              </div>
            </div>
            <div class="bottom" v-for="item in collectedPlaylists" :key="item.id">
              <div class="left">
                <img width="45px" height="45px" :src="item.url" alt="" class="playlist-cover" @click="openCollectedPlaylist(item)">
              </div>
              <div class="right playlist-info">
                <div style="font-weight: bold; cursor: pointer" @click="openCollectedPlaylist(item)">{{ item.name }}</div>
                <div style="display: flex; align-items: center; font-size: 12px; color: #736d6d; margin-top: 3px;">
                  <span>{{ item.num }}首</span>
                  <span style="margin-left: 10px;">{{ item.creator }}</span>
                </div>
              </div>
              <div class="action">
                <van-icon name="ellipsis" color="#736d6d" size="16" @click.stop="showPlaylistMenu(item, $event)"/>
              </div>
            </div>  
          </div>
        </van-tab>
        <van-tab title="歌单助手" name="c">
          <div class="tab">
            <div class="helper-card" v-for="(item, index) in helperTools" :key="index">
              <div class="helper-icon">
                <img width="45px" height="45px" :src="item.url" alt="" class="playlist-cover" @click="openRecommendPlaylist(item)">
              </div>
              <div class="helper-content">
                <div class="helper-title">{{ item.title }}</div>
                <div class="helper-desc" v-if="item.desc">{{ item.desc }}</div>
              </div>
              <div class="helper-action">
                <van-icon name="arrow-right" size="16" color="#999" />
              </div>
            </div>
            <div class="divider" />
            <div class="recommend-playlists">
              <div class="section-title">为你推荐歌单</div>
              <div class="recommend-list">
                <div class="recommend-item" v-for="(item, index) in recommendedPlaylists" :key="index" @click="openRecommendedPlaylist(item)">
                  <img :src="item.cover" alt="" class="recommend-cover" />
                  <div class="recommend-info">
                    <div class="recommend-name">{{ item.name }}</div>
                    <div class="recommend-count">{{ item.songCount }}首</div>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </van-tab>
      </van-tabs>
    </div>
  </div>
</template>

<script setup>
import { ref } from 'vue';
import { showToast } from 'vant';

const active = ref('a');
// 声明宫格数组
const gridList = ref([
  { id: 1, icon: "shop", text: '本地音乐' },
  { id: 2, icon: "shop-collect", text: '云盘' },
  { id: 3, icon: "goods-collect", text: '已购' },
  { id: 4, icon: "play-circle", text: '最近播放' },
  { id: 5, icon: "friends", text: '我的关注' },
  { id: 6, icon: "star", text: '收藏和赞' },
  { id: 7, icon: "volume", text: '我的播客' },
  { id: 8, icon: "music", text: '音乐应用' },
]);
// 定义创建歌单的数组
const playList = ref([
  {id:1,url:"https://imge.kugou.com/stdmusic/20220507/20220507113657285312.jpg",name:'90后回忆录',num:'30'},
  {id:2,url:"https://img2.baidu.com/it/u=1858292141,3587727348&fm=253&fmt=auto&app=138&f=JPEG?w=500&h=500",name:'车载音乐',num:'50'},
  {id:3,url:"https://imge.kugou.com/stdmusic/20240427/20240427191301775727.jpg",name:'助眠神曲',num:'70'},
]);

// 收藏歌单数据
const collectedPlaylists = ref([
  {id: 1,url: "https://picsum.photos/200/200?random=101",name: "网易云音乐官方歌单",num:"100",creator: "网易云音乐" },
  {id: 2,url: "https://picsum.photos/200/200?random=102",name: "华语流行经典",num: "88",creator: "音乐爱好者" },
  {id: 3,url: "https://picsum.photos/200/200?random=103",name: "纯音乐放松时刻",num: "66",creator: "治愈系音乐" },
  {id: 4,url: "https://picsum.photos/200/200?random=104",name: "摇滚不死",num: "50",creator: "摇滚青年" }
]);

// 歌单助手工具
const helperTools = ref([
  {id: "playlist",url: "https://img.shetu66.com/2024/03/06/170973229652128985.png",title: "整理相似歌曲",desc: "自动整理歌单中相似风格的歌曲"  },
  {id: "shuffle",url: "https://pic.616pic.com/bg_w1180/00/14/50/bi5w1CIVEC.jpg!/fw/1120",title: "智能推荐歌曲",desc: "根据歌单风格推荐合适的歌曲"  },
  {id: "trash", url: "https://pic.616pic.com/ys_bnew_img/00/10/46/R4ykl2k5Am.jpg",title: "清理无效歌曲",desc: "自动移除歌单中无法播放的歌曲"  },
  {id: "magic",url: "https://img.shetu66.com/2024/03/06/170973224284185578.png",title: "生成相似歌单",desc: "根据当前歌单生成相似风格的新歌单"  }
]);

// 推荐歌单
const recommendedPlaylists = ref([
  {id: 1,cover: "https://picsum.photos/200/200?random=201",name: "你的专属民谣",songCount: "45"  },
  {id: 2,cover: "https://picsum.photos/200/200?random=202",name: "深夜emo必备",songCount: "38"  },
  {id: 3,cover: "https://picsum.photos/200/200?random=203",name: "学习专注模式",songCount: "60"  }
]);

// 宫格点击事件
const openGrid = (item) => {
  showToast(`打开${item.text}`);
};

// 心动模式点击事件
const playHeartMode = () => {
  showToast('开启心动模式，为你推荐喜欢的音乐');
};

// 打开创建的歌单
const openPlaylist = (playlist) => {
  showToast(`打开歌单: ${playlist.name}`);
};

// 打开收藏的歌单
const openCollectedPlaylist = (playlist) => {
  showToast(`打开收藏歌单: ${playlist.name}`);
};

// 打开助手界面
const openRecommendPlaylist = (playlist) => {
  showToast(`打开推荐歌单: ${playlist.name}`);
};

// 打开推荐歌单
const openRecommendedPlaylist = (playlist) => {
  showToast(`打开推荐歌单: ${playlist.name}`);
};

// 显示歌单操作菜单
const showPlaylistMenu = (playlist, event) => {
  event.stopPropagation();
  showToast(`歌单操作: ${playlist.name}`);
  //这里可以显示一个操作菜单
};
</script>

<style lang="less" scoped>
.mine_parent {
  height: calc(100vh - 32px);
  background-color: #f4f4f4;
  padding: 10px;

  // 头像样式
  .avatar {
    display: flex;
    justify-content: space-between;
    align-items: center;

    .username {
      display: flex;
    }
  }

  // 宫格样式
  .grid {
    border-radius: 10px;
    overflow: hidden;
  }

  // 我喜欢的音乐样式
  .music {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 10px;
    background-color: #fff;
    padding: 10px;
    border-radius: 5px;

    .icon {
      width: 50px;
      height: 50px;
      display: flex;
      justify-content: center;
      align-items: center;
      background-color: rgba(0, 0, 0, 0.2);
      border-radius: 5px;
      background-image: url(https://imgessl.kugou.com/stdmusic/20220325/20220325010033953606.jpg);
      background-size: 100% 100%;
    }
  }
  // 收藏歌单
  .card{
    background-color: #fff;
    .tab{
      padding: 5px;
      .top{
        padding: 10px;
        display: flex;
        justify-content: space-between;
      }
      .bottom{
        padding: 10px;
        display: flex;
        align-items: center;
        .left{
          margin-right: 10px;
          img{
            border-radius: 5px;
          }
        }
        .right{
          flex: 1;
        }
      }
    }
    
    // 收藏歌单样式
    .playlist-cover {
      border-radius: 5px;
    }
    
    .playlist-info {
      flex: 1;
    }
    
    .action {
      padding: 5px;
    }
    
    // 歌单助手样式
    .helper-card {
      display: flex;
      align-items: center;
      padding: 16px;
      border-bottom: 1px solid #f0f0f0;
      
      .helper-icon {
        width: 40px;
        height: 40px;
        display: flex;
        justify-content: center;
        align-items: center;
        background-color: #f8f8f8;
        border-radius: 8px;
        margin-right: 16px;
      }
      
      .helper-content {
        flex: 1;
        
        .helper-title {
          font-size: 14px;
          font-weight: bold;
        }
        
        .helper-desc {
          font-size: 12px;
          color: #999;
          margin-top: 4px;
        }
      }
      
      .helper-action {
        color: #999;
      }
    }
    
    .divider {
      height: 8px;
      background-color: #f4f4f4;
    }
    
    .recommend-playlists {
      padding: 0 16px 16px;
      
      .section-title {
        font-size: 14px;
        font-weight: bold;
        padding: 16px 0 12px;
      }
      
      .recommend-list {
        display: flex;
        gap: 12px;
      }
      
      .recommend-item {
        width: 80px;
        
        .recommend-cover {
          width: 80px;
          height: 80px;
          border-radius: 6px;
          object-fit: cover;
        }
        
        .recommend-info {
          margin-top: 6px;
          
          .recommend-name {
            font-size: 12px;
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
          }
          
          .recommend-count {
            font-size: 10px;
            color: #999;
            margin-top: 2px;
          }
        }
      }
    }
  }
}
</style>